﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.ComponentModel;

namespace PatientInformationExtract.MainInterface.Views
{
    /// <summary>
    /// Interaction logic for RichTextBoxWithToolBar.xaml
    /// </summary>
    public partial class RichTextBoxWithToolBar : UserControl
    {
        public RichTextBox RichTextBox { get { return this.richTextBox; } }
        internal static Brush ObservationColor = new SolidColorBrush(Colors.Red);
        internal static Brush MedicalInterventionColor = new SolidColorBrush(Colors.Blue);
        internal static Brush TimeColor = new SolidColorBrush(Colors.Green);
        internal static Brush NormalColor = new SolidColorBrush(Colors.Black);
        public bool IsObservation { get { return this.tgbtnObservation.IsChecked == true; } }
        public bool IsMedicalIntervention { get { return this.tgbtnMedicalIntervention.IsChecked == true; } }
        public bool IsTime { get { return this.tgbtnTime.IsChecked == true; } }
        [Category("Common")]
        public bool IsReadOnly { set; get; }
        [Category("Common")]
        public ScrollBarVisibility VerticalScrollBarVisibility { set; get; }

        public RichTextBoxWithToolBar()
        {
            InitializeComponent();
            richTextBox.DataContext = this;
            tgbtnObservation.Foreground = ObservationColor;
            tgbtnMedicalIntervention.Foreground = MedicalInterventionColor;
            tgbtnTime.Foreground = TimeColor;
            tgbtnMedicalIntervention.IsChecked = true;
            tgbtnObservation.IsChecked = true;
            tgbtnTime.IsChecked = true;
            tgbtnMedicalIntervention.Focusable = false;
            tgbtnObservation.Focusable = false;
            tgbtnTime.Focusable = false;
            IsReadOnly = false;
            VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
        }

        private void menuObservation_Click(object sender, ExecutedRoutedEventArgs e)
        {
            this.richTextBox.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, ObservationColor);
        }

        private void menuMedicalIntervention_Click(object sender, ExecutedRoutedEventArgs e)
        {
            this.richTextBox.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, MedicalInterventionColor);
        }

        private void menuTime_Click(object sender, ExecutedRoutedEventArgs e)
        {            
            this.richTextBox.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, TimeColor);
        }

        private void menuNormal_Click(object sender, ExecutedRoutedEventArgs e)
        {
            this.richTextBox.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, NormalColor);
        }

        private void tgbtn_IsCheckedChange(object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(IsCheckedChangeEvent));
        }

        public static readonly RoutedEvent IsCheckedChangeEvent = EventManager.RegisterRoutedEvent("IsCheckedChange", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(RichTextBoxWithToolBar));

        public event RoutedEventHandler IsCheckedChange
        {
            add
            {
                this.AddHandler(IsCheckedChangeEvent, value);
            }
            remove
            {
                this.RemoveHandler(IsCheckedChangeEvent, value);
            }
        }

    }
}
